//
//  SingerDetailViewController.m
//  Coco_Music
//
//  Created by dlios on 15-6-24.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "SingerDetailViewController.h"

@interface SingerDetailViewController ()

@end

@implementation SingerDetailViewController
-(void)dealloc
{
    [_myTableView release];
    [_mySinger release];
    [_SDA release];
    [super dealloc];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.SDA =[NSMutableArray array];
    self.navigationItem.title = self.mySinger.title;
    
    self.myTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStylePlain];
    self.myTableView.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    self.myTableView.delegate =self;
    self.myTableView.dataSource =self;
    
    [self getData];
    
    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText = @"正在加载,请稍后";
    [self.HUD show:YES];
    
    
}
#define SingDetailConnect @"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%ld"
#define SingDetailConnect1 @"&size=1000&page=1&app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"

-(void)getData
{
    NSString *url =[NSString stringWithFormat:SingDetailConnect,self.SingerDetailID];
    NSString *url1 =[NSString stringWithFormat:url,SingDetailConnect1];
    [AFN_block NSString:url1 Blokc:^(id request) {
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:request];
       NSLog(@"歌手详情 == %@",dic);
        NSMutableArray *dataArray =[dic objectForKey:@"data"];
        for (NSMutableDictionary *myDic  in dataArray) {
            SingerDetail *singD =[[SingerDetail alloc]init];
            
            singD.singer_name = [myDic objectForKey:@"singer_name"];
            singD.singer_id  =[[myDic objectForKey:@"singer_id"]integerValue];
            singD.pic_url =[myDic objectForKey:@"pic_url"];
            [self.SDA addObject:singD];
            [singD release];
            
        }
        [self.myTableView reloadData];
        [self.HUD hide:YES];
        
    }];
    [self.myTableView.footer endRefreshing];
    [self.myTableView.header endRefreshing];
    [self.myTableView.footer beginRefreshing];
    [self.myTableView.header beginRefreshing];
    
 
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SpecialViewController *singD=[[SpecialViewController alloc]init];
  [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
   
    singD.SpecialID =[[self.SDA objectAtIndex:indexPath.row]singer_id];
    
    [self.navigationController pushViewController:singD animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.SDA.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier= @"cell";
  SingerDetailCell  *cell =[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell =[[SingerDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    
    }
    cell.singerD =[self.SDA objectAtIndex:indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [UIScreen mainScreen].bounds.size.height/5;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
